﻿// Study0406.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第四章 类和对象 联合体

#include <iostream>
using namespace std;

class ExamInfo
{
private:
	string name;

	enum { Grade,Pass,Percentage } mode;

	union 
	{
		char grade;
		bool pass;
		int percent;
	};
public:
	ExamInfo(string name, char grade) :name(name),mode(Grade),grade(grade){}
	ExamInfo(string name, bool pass) :name(name),mode(Pass),grade(pass){}
	ExamInfo(string name, int percent) :name(name),mode(Percentage),grade(percent){}
	void show();
};

void ExamInfo::show()
{
	cout << name << ":" ;
	switch (mode)
	{
	case Grade:
		cout << grade;
		break;
	case Pass:
		cout << pass;
		break;
	case Percentage:
		cout << percent;
		break;
	}
	cout << endl;
}


int main()
{
	ExamInfo course1("English", 'B');
	ExamInfo course2("Calculus", true);
	ExamInfo course3("C++ Programming", 85);
	course1.show();
	course2.show();
	course3.show();
	return 0;
}


